-Author: Concetta D'Amato and Riccardo Rigon
-License: this work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License
%reload_ext autoreload
%autoreload 2
%matplotlib inline
import os
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.colors as cl
from matplotlib import rc
import matplotlib.style as style
import math
import xarray as xr
import warnings
import plotly.graph_objects as go
import plotly.express as px
from geoframepy.timeseries import io_csv
from plotly.subplots import make_subplots
import pandas as pd
warnings.filterwarnings('ignore')
style.available
style.use('seaborn-whitegrid')
from GEOSPACE1D_Output import*
####### Plot settings #######
nice_fonts = {"legend.frameon": True, "legend.fancybox": True, "legend.facecolor": "white", "axes.edgecolor": "0.8","axes.linewidth": 0.6,"grid.linewidth":0.3,
# Use LaTeX to write all text
"text.usetex": False,"font.family": "Arial",
# Use 10pt font in plots, to match 10pt font in document
"axes.labelsize": 14,"font.size": 14,
# Make the legend/label fonts a little smaller
"legend.fontsize": 10,"xtick.labelsize": 14,"ytick.labelsize": 14,}
plt.rcParams.update(nice_fonts)
my_cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#045a8d","#023858"])
colors = ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7fà00']
project_path = os.path.dirname(os.getcwd())
#project_path= '/Users/concettadamato/Eclipse_workspace_12/GEOSPACE-1D_simulation'
os.chdir('C:/Users/marco/OMS_Project/OMS_Project_GEOSPACE-1D-main/output/Montecurto')
lab = 'Montecurto_ProsperoPM_totalstress_net_07'
file_name = 'OMS_'+lab+'_0000.nc'
ds = xr.open_dataset(file_name,engine='scipy')
ds
<xarray.Dataset>
Dimensions: (depth: 101, dualDepth: 101, time: 8741)
Coordinates:
* depth (depth) float64 -0.995 -0.985 -0.975 ... -0.005 0.0
* dualDepth (dualDepth) float64 -1.0 -0.99 -0.98 ... -0.01 0.0
* time (time) datetime64[ns] 2023-04-14T19:00:00 ... 202...
Data variables: (12/20)
psi (time, depth) float64 ...
psiIC (depth) float64 -0.005 -0.015 -0.025 ... -0.995 -1.0
rootDensityIC (depth) float64 0.0 0.0 0.0 ... 2.15e-05 0.0
Temperature (depth) float64 273.1 273.1 273.1 ... 273.1 293.1
theta (time, depth) float64 ...
waterVolume (time, depth) float64 ...
... ...
StressedTs (time, depth) float64 ...
StressedEs (time, depth) float64 ...
RootDensity (time, depth) float64 ...
errorWaterVolume (time) float64 1.277e-12 -1.445e-17 ... 1.326e-17
runOff (time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
controlVolume (depth) float64 0.01 0.01 0.01 ... 0.01 0.01 1.0
Attributes:
Description_of_the_problem: GEOSPACE simulation
Top_boundary_condition: Top Coupled
Bottom_boundary_condition: Bottom Free Drainage
path_top_boundary_condition: C:\Users\marco\OMS_Project\OMS_Projec...
path_bottom_boundary_condition: C:\Users\marco\OMS_Project\OMS_Projec...
path_grid: C:\Users\marco\OMS_Project\OMS_Projec...
time_delta:
swrc_model: {Water Depth,Van Genuchten}
soil_hydraulic_conductivity_model: {null,Mualem Van Genuchten}
interface_conductivity_model: maxprec = io_csv.pandas_read_OMS_timeseries(project_path + '/data/Montecurto/1/precip_1.csv',datetime_index=False)
#prec = io_csv.pandas_read_OMS_timeseries(project_path + '/data/Montecurto/1/precip_dry_1.csv',datetime_index=False)
prec.head()
| Datetime | 1 | |
|---|---|---|
| 0 | 2023-04-14 19:00:00 | 0.0 |
| 1 | 2023-04-14 20:00:00 | 0.0 |
| 2 | 2023-04-14 21:00:00 | 0.0 |
| 3 | 2023-04-14 22:00:00 | 0.0 |
| 4 | 2023-04-14 23:00:00 | 0.0 |
# Impostazioni iniziali
fig, ax = plt.subplots(2, 1, sharex='col', figsize=(1400/100, 800/100))
norm = matplotlib.colors.Normalize(vmin=0.05, vmax=0.4)
#norm = matplotlib.colors.Normalize(vmin=np.amin(ds.psi.values), vmax=np.amax(ds.psi.values))
# Grafico superiore
ax[0].plot(prec['Datetime'], prec['1'])
ax[0].set_ylabel('Precipitation-Irrigation [mm/h]', fontname='Arial',size=14)
ax[0].tick_params(axis='both', which='major', labelsize=14)
# Modifica dei colori della griglia del primo plot
ax[0].grid(color='lightgray', linestyle='-', linewidth=0.8)
# Aggiunta del contorno esterno scuro al primo grafico
ax[0].spines['top'].set_color('black')
ax[0].spines['bottom'].set_color('black')
ax[0].spines['left'].set_color('black')
ax[0].spines['right'].set_color('black')
# Grafico inferiore con la color bar
a = ds.theta.plot(ax=ax[1], y='depth', add_colorbar=False, cmap=my_cmap, norm=norm)
ax[1].set_ylabel('Depth [m]', fontname='Arial',size=14)
ax[1].set_xlabel('')
ax[1].xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
ax[1].xaxis.set_tick_params(rotation=0)
ax[1].tick_params(axis='both', which='major', labelsize=14)
# Aggiunta della color bar
cbar_ax = fig.add_axes([0.91, 0.12, 0.02, 0.36])
sm = plt.cm.ScalarMappable(cmap=my_cmap, norm=norm)
cbar = fig.colorbar(sm, cax=cbar_ax)
cbar.set_label('$\\theta$ [-]', rotation=0, labelpad=22, fontname='Arial',size=14)
# Settaggio dei valori della color bar
#cbar.set_ticks([val for val in np.linspace(np.amin(ds.psi.values), np.amax(ds.psi.values), num=5)])
cbar.set_ticks([val for val in np.linspace(0.05,0.4, num=5)])
cbar.ax.tick_params(labelsize=14)
# Salva l'immagine
#plt.savefig('ProsperoMontecuro_totalstress_06_rad-theta.png', dpi=300, bbox_inches='tight') # Imposta il nome desiderato per l'immagine e regola dpi e bbox se necessario
plt.show()
# Impostazioni iniziali
fig, ax = plt.subplots(2, 1, sharex='col', figsize=(1400/100, 800/100))
#norm = matplotlib.colors.Normalize(vmin=0.05, vmax=0.4)
norm = matplotlib.colors.Normalize(vmin=np.amin(ds.StressWaters.values), vmax=np.amax(ds.StressWaters.values))
# Grafico superiore
ax[0].plot(prec['Datetime'], prec['1'])
ax[0].set_ylabel('Precipitation-Irrigation [mm/h]', fontname='Arial',size=14)
ax[0].tick_params(axis='both', which='major', labelsize=14)
# Modifica dei colori della griglia del primo plot
ax[0].grid(color='lightgray', linestyle='-', linewidth=0.8)
# Aggiunta del contorno esterno scuro al primo grafico
ax[0].spines['top'].set_color('black')
ax[0].spines['bottom'].set_color('black')
ax[0].spines['left'].set_color('black')
ax[0].spines['right'].set_color('black')
# Grafico inferiore con la color bar
a = ds.StressWaters.plot(ax=ax[1], y='depth', add_colorbar=False, cmap=my_cmap, norm=norm)
ax[1].set_ylabel('Depth [m]', fontname='Arial',size=14)
ax[1].set_xlabel('')
ax[1].xaxis.set_major_formatter(mdates.DateFormatter('%b %d'))
ax[1].xaxis.set_tick_params(rotation=0)
ax[1].tick_params(axis='both', which='major', labelsize=14)
# Aggiunta della color bar
cbar_ax = fig.add_axes([0.91, 0.12, 0.02, 0.36])
sm = plt.cm.ScalarMappable(cmap=my_cmap, norm=norm)
cbar = fig.colorbar(sm, cax=cbar_ax)
cbar.set_label('StressWaters [-]', rotation=90, labelpad=22, fontname='Arial',size=14)
# Settaggio dei valori della color bar
cbar.set_ticks([val for val in np.linspace(np.amin(ds.StressWaters.values), np.amax(ds.StressWaters.values), num=5)])
#cbar.set_ticks([val for val in np.linspace(0.05,0.4, num=5)])
cbar.ax.tick_params(labelsize=14)
# Salva l'immagine
#plt.savefig('ProsperoMontecuro_totalstress_net_06_StressWaters.png', dpi=300, bbox_inches='tight') # Imposta il nome desiderato per l'immagine e regola dpi e bbox se necessario
#plt.savefig('ProsperoMontecuro_totalstress_07_StressWaters.png', dpi=300, bbox_inches='tight') # Imposta il nome desiderato per l'immagine e regola dpi e bbox se necessario
plt.show()
root_depth = -0.8
evaporation_layer_depth = -0.2
#myDepth = [-0.10,-0.30,-0.50,-0.70,-1.00,-1.5]
myDepth = [-0.10,-0.30,-0.50,-0.70,-0.85,-1.00]
myDate = ['2023-04-14 19:00','2023-07-01 01:00','2023-07-03 01:00','2023-07-04 01:00','2023-07-05 01:00','2023-07-08 01:00','2023-07-25 01:00']
#myDate = ['2023-10-01 01:00','2023-10-21 01:00']#,'2023-10-21 01:00','2023-06-22 01:00','2023-06-23 01:00','2023-06-24 01:00','2023-06-25 01:00','2023-06-26 01:00']
colorblind= ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f']
fig = go.Figure()
# Creare subplot con dimensioni personalizzate
#fig = make_subplots(rows=2, cols=1, shared_xaxes=True,
# subplot_titles=['a) Water pressure at different depths', 'b) Water content at different depths'],
# row_heights=[0.5, 0.5],
# vertical_spacing=0.19)
# Imposta la dimensione del testo dei titoli delle subplot
#for i in range(1, 3):
# fig.layout.annotations[i-1].update(font=dict(size=22))
# Subplot a
#for i in range(len(myDepth)):
# fig.add_trace(go.Scatter(x=ds.time, y=ds.psi.sel(depth=myDepth[i], method='nearest'), name=str(myDepth[i])+' m',line=dict(width=2,color=colorblind[i])), row=1, col=1)
# Subplot b
for i in range(len(myDepth)):
fig.add_trace(go.Scatter(x=ds.time, y=ds.theta.sel(depth=myDepth[i], method='nearest'), name=str(myDepth[i])+' m',showlegend=True,line=dict(width=2,color=colorblind[i])))
# Aggiornare il layout del grafico
fig.update_layout(
height=500, width=1300,
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
font=dict(size=22),
plot_bgcolor="white",
legend=dict(orientation='h', y=1.15, x=0.25),
)
# Subplot a
#fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', row=1, col=1, zeroline=True,
# zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
#fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', row=1, col=1, zeroline=True,
# zerolinecolor="darkgray", zerolinewidth=1, title={"text": 'ψ [m]', "font": {"size": 20, "family": "Arial"}}, tickangle=0,tickfont=dict(size=20))
# Subplot b
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,
zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,
zerolinecolor="darkgray", zerolinewidth=1, title={"text": 'Water Content θ [-]', "font": {"size": 20, "family": "Arial"}},tickangle=0,tickfont=dict(size=20))
#fig.add_shape(type="rect",xref="paper",yref="paper",x0=fig['layout']['xaxis']['domain'][0],y0=fig['layout']['yaxis']['domain'][0],x1=fig['layout']['xaxis']['domain'][1],y1=fig['layout']['yaxis']['domain'][1],line=dict(color="darkgray", width=2))
#fig.add_shape(type="rect",xref="paper",yref="paper",x0=fig['layout']['xaxis2']['domain'][0],y0=fig['layout']['yaxis2']['domain'][0],x1=fig['layout']['xaxis2']['domain'][1],y1=fig['layout']['yaxis2']['domain'][1],line=dict(color="darkgray", width=2))
fig.add_shape(type="rect", xref="paper", yref="paper", x0=0, y0=0, x1=1, y1=1, line=dict(color="darkgray", width=2))
fig.show()
# Creare subplot con dimensioni personalizzate
fig = make_subplots(rows=1, cols=2, shared_yaxes=True,
subplot_titles=['a) Water pressure at different times', 'b) Water content at different times'],
column_widths=[0.5, 0.5],
horizontal_spacing=0.1)
# Imposta la dimensione del testo dei titoli delle subplot
for i in range(1, 3):
fig.layout.annotations[i-1].update(font=dict(size=22))
# Subplot a
fig.add_trace(go.Scatter(x=ds.psi.sel(time=myDate[0]), y=ds.depth.values[:] ,name='Initial Condition',line=dict(width=2.5,color='black')), row=1, col=1)
for i in range(1, len(myDate)):
fig.add_trace(go.Scatter(x=ds.psi.sel(time=myDate[i]), y=ds.depth.values[:] ,name=str(myDate[i]),line=dict(width=2.5,color=colors[i-1])), row=1, col=1)
# Subplot b
fig.add_trace(go.Scatter(x=ds.theta.sel(time=myDate[0]), y=ds.depth.values[:] ,name=str(myDate[i]), showlegend=False, line=dict(width=2.5,color='black')), row=1, col=2)
for i in range(1, len(myDate)):
fig.add_trace(go.Scatter(x=ds.theta.sel(time=myDate[i]), y=ds.depth.values[:] ,name=str(myDate[i]), showlegend=False, line=dict(width=2.5,color=colors[i-1])), row=1, col=2)
# Aggiornare il layout del grafico
fig.update_layout(
height=800, width=1400,
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
font=dict(size=22),
plot_bgcolor="white",
#legend=dict(orientation='h', y=1.15, x=0.2),
)
## Subplot a
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', row=1, col=1, zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20),title={"text": 'ψ [m]', "font": {"size": 20, "family": "Arial"}})
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', row=1, col=1, zeroline=True, zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20),title={"text": 'Soil depth [m]', "font": {"size": 20, "family": "Arial"}})
# Subplot b
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', row=1, col=2, zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20),title={"text": 'θ [-]', "font": {"size": 22, "family": "Arial"}})
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', row=1, col=2, zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20))
fig.add_shape(type="rect",xref="paper",yref="paper",x0=fig['layout']['xaxis']['domain'][0],y0=fig['layout']['yaxis']['domain'][0],x1=fig['layout']['xaxis']['domain'][1],y1=fig['layout']['yaxis']['domain'][1],line=dict(color="darkgray", width=2))
fig.add_shape(type="rect",xref="paper",yref="paper",x0=fig['layout']['xaxis2']['domain'][0],y0=fig['layout']['yaxis2']['domain'][0],x1=fig['layout']['xaxis2']['domain'][1],y1=fig['layout']['yaxis2']['domain'][1],line=dict(color="darkgray", width=2))
fig.show()
# Creare subplot con dimensioni personalizzate
fig = go.Figure()
# Subplot a
fig.add_trace(go.Scatter(x=ds.theta.sel(time=myDate[0]), y=ds.depth.values[:100] ,name='Initial Condition',line=dict(width=2.5,color='black')))
for i in range(1, len(myDate)):
fig.add_trace(go.Scatter(x=ds.theta.sel(time=myDate[i]), y=ds.depth.values[:100] ,name=str(myDate[i]),line=dict(width=2.5,color=colors[i-1])))
fig.add_shape(go.layout.Shape(type='line', x0=0, x1=1, y0=root_depth, y1=root_depth, line=dict(color='black', width=2, dash ='dash')))
fig.add_shape(go.layout.Shape(type='line', x0=0, x1=1, y0=evaporation_layer_depth, y1=evaporation_layer_depth, line=dict(color='black', width=2, dash ='dashdot')))
# Adding Annotation on subplot a
fig.add_annotation(go.layout.Annotation(text="evaporation depth", x=0.01,y=0.81,showarrow=False,xref="paper",yref="paper",font=dict(size=18)))
fig.add_annotation(go.layout.Annotation(text="root depth", x=0.01,y=0.23,showarrow=False,xref="paper",yref="paper",font=dict(size=18)))
# Aggiornare il layout del grafico
fig.update_layout(
height=800, width=800,
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
font=dict(size=22),
plot_bgcolor="white",
#legend=dict(orientation='h', y=1.15, x=0.2),
)
## Subplot
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,range=[0.1,0.45],zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20),title={"text": 'Water Content [-]', "font": {"size": 20, "family": "Arial"}})
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20),title={"text": 'Soil depth [m]', "font": {"size": 20, "family": "Arial"}})
fig.add_shape(type="rect", xref="paper", yref="paper", x0=0, y0=0, x1=1, y1=1, line=dict(color="darkgray", width=2))
fig.show()
fig = px.line()
fig.add_trace(go.Scatter(y=ds.StressWater, x=ds.time.values[:], mode='lines',line=dict(color="black", width=2.5)))
fig.update_layout(
height=400, width=1200,
title='',
#xaxis_title="Date"
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
yaxis_title="[-]",
#legend_title="Date",
font=dict(size=16),
legend=dict(yanchor="top", y=0.99, xanchor="right", x=0.99, title=""),
plot_bgcolor="white",
)
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_yaxes(title={"text": 'Representative Water Stress [-]', "font": {"size": 20, "family": "Arial"}},showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1,tickfont=dict(size=20))
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.show()
fig = px.line()
fig.add_trace(go.Scatter(y=ds.darcyVelocity.sel(dualDepth=ds.dualDepth[0], time=ds.time.values[:]).values*-3600000, x=ds.time.values[:], mode='lines',line=dict(color="black", width=2.5)))
fig.update_layout(
height=400, width=1200,
title='',
#xaxis_title="Date"
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
yaxis_title="",
#legend_title="Date",
font=dict(size=16),
legend=dict(yanchor="top", y=0.99, xanchor="right", x=0.99, title=""),
plot_bgcolor="white",
)
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_yaxes(title={"text": 'Bottom Flux [mm/h]', "font": {"size": 20, "family": "Arial"}},showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1,tickfont=dict(size=20))
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.show()
os.chdir(project_path+'/output/Montecurto')
dfE= pd.read_csv('Evaporation_1_'+lab+'.csv',skiprows=6,parse_dates=[1])
dfE = dfE.drop(['Format'],axis=1)
dfE.columns = ['Datetime','E_sim']
dfT = pd.read_csv('Transpiration_1_'+lab+'.csv',skiprows=6,parse_dates=[1])
dfT = dfT.drop(['Format'],axis=1)
dfT.columns = ['Datetime','T_sim']
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Add traces
fig.add_trace(
go.Scatter(x=dfT.Datetime, y=dfT.T_sim, name="Evaporation",line = dict(color = '#117733', width=2)),
secondary_y=False,
)
fig.add_trace(
go.Scatter(x=dfE.Datetime, y=dfE.E_sim, name="Transpiration",line = dict(color = '#EE7733', width=2)),
secondary_y=True,
)
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1)
fig.update_yaxes(title={"text": 'Transpiration [mm/h]', "font": {"size": 20, "family": "Arial"}}, secondary_y=False,title_standoff=20,tickfont=dict(size=20))
fig.update_yaxes(title={"text": 'Evaporation [mm/h]', "font": {"size": 20, "family": "Arial"}}, secondary_y=True,title_standoff=20,tickfont=dict(size=20))
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_layout(
height=500, width=1400,
#title='OliveTree data',
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
plot_bgcolor="white",
font=dict(size=22),
legend=dict(orientation='h', y=1.15, x=0.35)
)
fig.show()
fig = px.line()
fig.add_trace(go.Scatter(x=dfT['Datetime'], y=dfT['T_sim'], mode='lines',line=dict(color="green", width=1.5)))
fig.update_layout(
height=500, width=1400,
title='',
#xaxis_title="Date"
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
#legend_title="Date",
font=dict(size=20),
legend=dict(yanchor="top", y=0.99, xanchor="left", x=0.01, title=""),
plot_bgcolor="white",
)
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_yaxes(title={"text": 'Transpiration [mm/h]', "font": {"size": 20, "family": "Arial"}},showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1,tickfont=dict(size=20))
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.show()
dfET = pd.read_csv('EvapoTranspiration_1_'+lab+'.csv',skiprows=6,parse_dates=[1])
dfET = dfET.drop(['Format'],axis=1)
dfET.columns = ['Datetime','ET_sim']
fig = px.line()
fig.add_trace(go.Scatter(x=dfET['Datetime'], y=dfET['ET_sim'], mode='lines',line=dict(color="green", width=1.5)))
fig.update_layout(
height=500, width=1400,
title='',
#xaxis_title="Date"
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
#legend_title="Date",
font=dict(size=20),
legend=dict(yanchor="top", y=0.99, xanchor="left", x=0.01, title=""),
plot_bgcolor="white",
)
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_yaxes(title={"text": 'Evapotranspiration [mm/h]', "font": {"size": 20, "family": "Arial"}},showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1,tickfont=dict(size=20))
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.show()
#fig.write_html('ProsperoMontecuro_totalstress_07_EvapoTranspiration.html')
dfET.head()
| Datetime | ET_sim | |
|---|---|---|
| 0 | 2023-04-14 19:00:00 | 0.040590 |
| 1 | 2023-04-14 20:00:00 | 0.035707 |
| 2 | 2023-04-14 21:00:00 | 0.013602 |
| 3 | 2023-04-14 22:00:00 | 0.007495 |
| 4 | 2023-04-14 23:00:00 | 0.010473 |
dfET.set_index('Datetime',inplace=True)
dfET.head()
| ET_sim | |
|---|---|
| Datetime | |
| 2023-04-14 19:00:00 | 0.040590 |
| 2023-04-14 20:00:00 | 0.035707 |
| 2023-04-14 21:00:00 | 0.013602 |
| 2023-04-14 22:00:00 | 0.007495 |
| 2023-04-14 23:00:00 | 0.010473 |
dfETg=dfET.resample('D').sum()
dfETg.head()
| ET_sim | |
|---|---|
| Datetime | |
| 2023-04-14 | 0.107867 |
| 2023-04-15 | 3.333873 |
| 2023-04-16 | 3.077985 |
| 2023-04-17 | 2.303740 |
| 2023-04-18 | 3.889938 |
dfETg.reset_index(inplace=True)
dfETg.head()
| Datetime | ET_sim | |
|---|---|---|
| 0 | 2023-04-14 | 0.107867 |
| 1 | 2023-04-15 | 3.333873 |
| 2 | 2023-04-16 | 3.077985 |
| 3 | 2023-04-17 | 2.303740 |
| 4 | 2023-04-18 | 3.889938 |
fig = px.line()
fig.add_trace(go.Scatter(x=dfETg['Datetime'], y=dfETg['ET_sim'], mode='lines',line=dict(color="green", width=1.5)))
fig.update_layout(
height=500, width=1400,
title='',
#xaxis_title="Date"
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
#legend_title="Date",
font=dict(size=20),
legend=dict(yanchor="top", y=0.99, xanchor="left", x=0.01, title=""),
plot_bgcolor="white",
)
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_yaxes(title={"text": 'Evapotranspiration [mm/d]', "font": {"size": 20, "family": "Arial"}},showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1,tickfont=dict(size=20))
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.show()
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# Add traces
fig.add_trace(
go.Scatter(x=dfET.Datetime, y=dfET.ET_sim, name="Hourly ET",line = dict(color = '#EE7733', width=2)),
secondary_y=False,
)
fig.add_trace(
go.Scatter(x=dfETg.Datetime, y=dfETg.ET_sim, name="Daily ET",line = dict(color = '#117733', width=3)),
secondary_y=True,
)
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray',zeroline=True,zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True,tickfont=dict(size=20), tickformat='%b %d')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1)
fig.update_yaxes(title={"text": 'EvapoTranspiration [mm/h]', "font": {"size": 20, "family": "Arial"}}, secondary_y=False,title_standoff=20,tickfont=dict(size=20))
fig.update_yaxes(title={"text": 'EvapoTranspiration [mm/d]', "font": {"size": 20, "family": "Arial"}}, secondary_y=True,title_standoff=20,tickfont=dict(size=20))
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
fig.update_layout(
height=500, width=1400,
#title='OliveTree data',
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
plot_bgcolor="white",
font=dict(size=22),
legend=dict(orientation='h', y=1.15, x=0.35)
)
fig.show()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_22536\3538150904.py in <module> 5 6 fig.add_trace( ----> 7 go.Scatter(x=dfET.Datetime, y=dfET.ET_sim, name="Hourly ET",line = dict(color = '#EE7733', width=2)), 8 secondary_y=False, 9 ) ~\anaconda3\envs\geoframe_parigi\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 5485 ): 5486 return self[name] -> 5487 return object.__getattribute__(self, name) 5488 5489 def __setattr__(self, name: str, value) -> None: AttributeError: 'DataFrame' object has no attribute 'Datetime'
# Creare il grafico
fig = px.line()
fig.add_trace(go.Scatter(y=ds.errorWaterVolume, x=ds.time.values[:], mode='lines',line=dict(color="black", width=1.5)))
# Aggiornare il layout del grafico
fig.update_layout(
height=400, width=1200,
title='',
font_family="Arial",
font_color="Black",
title_font_family="Arial",
title_font_color="Black",
yaxis_title="",
font=dict(size=18),
legend=dict(yanchor="top", y=0.99, xanchor="right", x=0.99, title=""),
plot_bgcolor="white",
)
# Aggiungere una forma
fig.add_shape(type="rect", xref="paper", yref="paper", x0=fig['layout']['xaxis']['domain'][0], y0=fig['layout']['yaxis']['domain'][0], x1=fig['layout']['xaxis']['domain'][1], y1=fig['layout']['yaxis']['domain'][1], line=dict(color="darkgray", width=2))
# Aggiornare l'aspetto dell'asse y
fig.update_yaxes(title={"text": 'Volume error at each time step [m]', "font": {"size": 20, "family": "Arial"}},showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1, tickfont=dict(size=20), showexponent='last', exponentformat='e')
# Aggiornare l'aspetto dell'asse x
fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='lightgray', zeroline=True, zerolinecolor="darkgray", zerolinewidth=1, showticklabels=True, tickfont=dict(size=20), tickformat='%b %d')
# Mostrare il grafico
fig.show()